/*
 * Common utility routines file.
 */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<signal.h>
#include<fcntl.h>
#include <stdarg.h>

#include "util.h"

void LOG(int sev, char* format, ...) {

    switch(sev){
    case DEBUG:
        printf("DEBUG: ");
        break;
    case INFO:
        printf("INFO: ");
        break;
    case WARN:
        printf("WARNING: ");
        break;
    case ERROR:
        printf("ERROR: ");
        break;
    case CRITICAL:
        printf("CRITICAL: ");
        break;
    default:
        break;
    }
    
    va_list args;
    va_start(args,format);
    vfprintf(stdout, format,args);
    va_end(args);
    fprintf(stdout, "\n");
    fflush(stdout);
}

int errexit(const char *format, ...) {
    va_list args;
    va_start(args,format);
    vfprintf(stderr, format,args);
    va_end(args);
    fprintf(stdout, "\n");
    exit(1);
}

